package top.fangw.admin.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.RequiredArgsConstructor;
import top.fangw.admin.pojo.entity.SysRoleJoinApplication;
import top.fangw.admin.mapper.SysRoleJoinApplicationMapper;
import top.fangw.admin.service.ISysRoleJoinApplicationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.fangw.common.api.vo.InitRoleJoinApplication;
import top.fangw.common.mybatis.annotation.DyDataSource;

/**
 * <p>
 * 用途：角色与应用的关联关系表 服务实现类
 * </p>
 *
 * @author fangw
 * @since 2024-03-13
 */
@Service
@DS("base_info")
@RequiredArgsConstructor
public class SysRoleJoinApplicationServiceImpl extends ServiceImpl<SysRoleJoinApplicationMapper, SysRoleJoinApplication> implements ISysRoleJoinApplicationService {

    private final SysRoleJoinApplicationMapper sysRoleJoinApplicationMapper;
    @Override
    @DyDataSource(tenantId = "#initRoleJoinApplication.tenantId", autoTenantId = false)
    public void initRoleJoinApplication(InitRoleJoinApplication initRoleJoinApplication) {
        System.out.println("initRoleJoinApplication = " + initRoleJoinApplication);
        if (initRoleJoinApplication.getInitRoleJoinApplicationList() != null && initRoleJoinApplication.getInitRoleJoinApplicationList().size() > 0) {
            initRoleJoinApplication.getInitRoleJoinApplicationList().forEach(item -> {
                SysRoleJoinApplication sysRoleJoinApplication = BeanUtil.copyProperties(item, SysRoleJoinApplication.class);
                this.baseMapper.insert(sysRoleJoinApplication);
            });
        }
    }

    @Override
    @DyDataSource(tenantId = "#sysRoleJoinApplication.tenantId", autoTenantId = false)
    public void insert(SysRoleJoinApplication sysRoleJoinApplication) {
        int insert = sysRoleJoinApplicationMapper.insert(sysRoleJoinApplication);
        System.out.println("insert = " + sysRoleJoinApplication);
    }
}
